<template>
	<view class="">
		<view class="content">
			<view class="title">收银员</view>
			<form>
				<view class="inner">
					<text class="text" space="emsp">姓  名：</text>
					<input class="input" placeholder="请输入收银员姓名" v-model="name"/>
				</view>
				<view class="inner">
					<text class="text" >电话号码：</text>
					<input class="input"  maxlength="11" placeholder="请输入电话号码"  v-model="phone"/>
				</view>
				<!-- <view class="inner">
					<text class="text" space="emsp">权  限：</text>
					<radio-group>
						<view class="input">
							<label class="checkbox">
								权限1：<radio value="收银员1"  color="#F76968"/>
								权限2：<radio value="收银员2"  color="#F76968" />
							</label>
						</view>
					</radio-group>
				</view> -->
				<view class="">
					<button class="button"   @click="Add">添加</button>
				</view>
			</form>
		</view>
	</view>
</template>

<script>
	import eonfox from '@/components/eonfox/eonfox.js';
	import fns from '@/components/eonfox/fns.js';
	var ef=new eonfox();
	export default {
		data() {
			return {
				mchId:'',
				name:'',
				phone:'',
				mchName:''
			}
		},
		onLoad() {
			var _this=this;
			ef.submit({
				request:{
					mch:['MERCHANTSELF'],
					cashier:['MERCHANTCASHIERSELF']
				},
				callback(data){
					var re=fns.checkError(data,['mch'],function(errno,error){
						uni.showToast({
							title:error,
							icon:'none'
						})
					})
					console.log(re)
					if(re.mch[0]){
						_this.mchId=re.mch[0].id
					}
					if(re.cashier && re.cashier.merchant_cashier_name){
						_this.mchName = re.cashier.merchant_cashier_name
					}
				}
			})
		},
		methods: {
			Add(){
				var that=this;
				ef.submit({
					request:{
						s:['MERCHANTCASHIERSELFADD',[{phone:that.phone,merchant_id:that.mchId,nickname:that.name,}]]
						},
					callback(data){
						var re=fns.checkError(data,['s'],function(errno,error){
							uni.showToast({
								title:error,
								icon:'none'
							})
						})
						if(re.s){
							uni.showToast({
								title:'添加收银员成功',
								success() {
									setTimeout(function(){
										uni.navigateBack({
											delta:1
										})
									},3000)
								}
							})
						}
						console.log(re)
					}
				})
			}
		}
	}
</script>

<style>
	.content{
		display: flex;
		flex-direction: column;
		flex: 1;
		margin: 5px 10px;
		color: #333333;
	}
	.inner{
		display: flex;
		flex-direction: row;
		flex: 1;
		height: 50upx;
		margin: 30upx 3px;
		padding:8px 5px;
		border: #e4e4e4 solid 1px;
		border-radius: 3px;
		font-size: 14px;
		justify-content: space-between;
		line-height: 50upx;
	}
	.inner input{
		width: 100%;
		height: 100%;
	}
	.title{
		padding: 30upx;
		height: 200upx;
		line-height: 200upx;
		background-color:#F76260;
		color: #FFFFFF;
		text-align: center;
		font-size:38upx;
		border-radius: 10upx;
	}
	.text{
		flex: 1;
		text-align: left;
	}
	.input{
		flex: 3;
	}
	.button{
		background-color: #f76260;
		color: #FFFFFF;
		margin-top: 50upx;
		width: 100%;
		height: 80upx;
		line-height: 80upx;
		font-size: 32upx;
	}
</style>
